// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Mapping;

/// <summary>
/// <para>A variant of text that trades scoring and efficiency of positional queries for space efficiency. This field<br/>effectively stores data the same way as a text field that only indexes documents (index_options: docs) and<br/>disables norms (norms: false). Term queries perform as fast if not faster as on text fields, however queries<br/>that need positions such as the match_phrase query perform slower as they need to look at the _source document<br/>to verify whether a phrase matches. All queries return constant scores that are equal to 1.0.</para>
/// </summary>
public sealed partial class MatchOnlyTextProperty : IProperty
{
	/// <summary>
	/// <para>Allows you to copy the values of multiple fields into a group<br/>field, which can then be queried as a single field.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("copy_to")]
	[JsonConverter(typeof(SingleOrManyFieldsConverter))]
	public Elastic.Clients.Elasticsearch.Serverless.Fields? CopyTo { get; set; }

	/// <summary>
	/// <para>Multi-fields allow the same string value to be indexed in multiple ways for different purposes, such as one<br/>field for search and a multi-field for sorting and aggregations, or the same string value analyzed by different analyzers.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("fields")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? Fields { get; set; }

	/// <summary>
	/// <para>Metadata about the field.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("meta")]
	public IDictionary<string, string>? Meta { get; set; }

	[JsonInclude, JsonPropertyName("type")]
	public string Type => "match_only_text";
}

/// <summary>
/// <para>A variant of text that trades scoring and efficiency of positional queries for space efficiency. This field<br/>effectively stores data the same way as a text field that only indexes documents (index_options: docs) and<br/>disables norms (norms: false). Term queries perform as fast if not faster as on text fields, however queries<br/>that need positions such as the match_phrase query perform slower as they need to look at the _source document<br/>to verify whether a phrase matches. All queries return constant scores that are equal to 1.0.</para>
/// </summary>
public sealed partial class MatchOnlyTextPropertyDescriptor<TDocument> : SerializableDescriptor<MatchOnlyTextPropertyDescriptor<TDocument>>, IBuildableDescriptor<MatchOnlyTextProperty>
{
	internal MatchOnlyTextPropertyDescriptor(Action<MatchOnlyTextPropertyDescriptor<TDocument>> configure) => configure.Invoke(this);

	public MatchOnlyTextPropertyDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Fields? CopyToValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? FieldsValue { get; set; }
	private IDictionary<string, string>? MetaValue { get; set; }

	/// <summary>
	/// <para>Allows you to copy the values of multiple fields into a group<br/>field, which can then be queried as a single field.</para>
	/// </summary>
	public MatchOnlyTextPropertyDescriptor<TDocument> CopyTo(Elastic.Clients.Elasticsearch.Serverless.Fields? copyTo)
	{
		CopyToValue = copyTo;
		return Self;
	}

	/// <summary>
	/// <para>Multi-fields allow the same string value to be indexed in multiple ways for different purposes, such as one<br/>field for search and a multi-field for sorting and aggregations, or the same string value analyzed by different analyzers.</para>
	/// </summary>
	public MatchOnlyTextPropertyDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? fields)
	{
		FieldsValue = fields;
		return Self;
	}

	public MatchOnlyTextPropertyDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public MatchOnlyTextPropertyDescriptor<TDocument> Fields(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	/// <summary>
	/// <para>Metadata about the field.</para>
	/// </summary>
	public MatchOnlyTextPropertyDescriptor<TDocument> Meta(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		MetaValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (CopyToValue is not null)
		{
			writer.WritePropertyName("copy_to");
			JsonSerializer.Serialize(writer, CopyToValue, options);
		}

		if (FieldsValue is not null)
		{
			writer.WritePropertyName("fields");
			JsonSerializer.Serialize(writer, FieldsValue, options);
		}

		if (MetaValue is not null)
		{
			writer.WritePropertyName("meta");
			JsonSerializer.Serialize(writer, MetaValue, options);
		}

		writer.WritePropertyName("type");
		writer.WriteStringValue("match_only_text");
		writer.WriteEndObject();
	}

	MatchOnlyTextProperty IBuildableDescriptor<MatchOnlyTextProperty>.Build() => new()
	{
		CopyTo = CopyToValue,
		Fields = FieldsValue,
		Meta = MetaValue
	};
}

/// <summary>
/// <para>A variant of text that trades scoring and efficiency of positional queries for space efficiency. This field<br/>effectively stores data the same way as a text field that only indexes documents (index_options: docs) and<br/>disables norms (norms: false). Term queries perform as fast if not faster as on text fields, however queries<br/>that need positions such as the match_phrase query perform slower as they need to look at the _source document<br/>to verify whether a phrase matches. All queries return constant scores that are equal to 1.0.</para>
/// </summary>
public sealed partial class MatchOnlyTextPropertyDescriptor : SerializableDescriptor<MatchOnlyTextPropertyDescriptor>, IBuildableDescriptor<MatchOnlyTextProperty>
{
	internal MatchOnlyTextPropertyDescriptor(Action<MatchOnlyTextPropertyDescriptor> configure) => configure.Invoke(this);

	public MatchOnlyTextPropertyDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Fields? CopyToValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? FieldsValue { get; set; }
	private IDictionary<string, string>? MetaValue { get; set; }

	/// <summary>
	/// <para>Allows you to copy the values of multiple fields into a group<br/>field, which can then be queried as a single field.</para>
	/// </summary>
	public MatchOnlyTextPropertyDescriptor CopyTo(Elastic.Clients.Elasticsearch.Serverless.Fields? copyTo)
	{
		CopyToValue = copyTo;
		return Self;
	}

	/// <summary>
	/// <para>Multi-fields allow the same string value to be indexed in multiple ways for different purposes, such as one<br/>field for search and a multi-field for sorting and aggregations, or the same string value analyzed by different analyzers.</para>
	/// </summary>
	public MatchOnlyTextPropertyDescriptor Fields(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? fields)
	{
		FieldsValue = fields;
		return Self;
	}

	public MatchOnlyTextPropertyDescriptor Fields<TDocument>(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public MatchOnlyTextPropertyDescriptor Fields<TDocument>(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	/// <summary>
	/// <para>Metadata about the field.</para>
	/// </summary>
	public MatchOnlyTextPropertyDescriptor Meta(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		MetaValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (CopyToValue is not null)
		{
			writer.WritePropertyName("copy_to");
			JsonSerializer.Serialize(writer, CopyToValue, options);
		}

		if (FieldsValue is not null)
		{
			writer.WritePropertyName("fields");
			JsonSerializer.Serialize(writer, FieldsValue, options);
		}

		if (MetaValue is not null)
		{
			writer.WritePropertyName("meta");
			JsonSerializer.Serialize(writer, MetaValue, options);
		}

		writer.WritePropertyName("type");
		writer.WriteStringValue("match_only_text");
		writer.WriteEndObject();
	}

	MatchOnlyTextProperty IBuildableDescriptor<MatchOnlyTextProperty>.Build() => new()
	{
		CopyTo = CopyToValue,
		Fields = FieldsValue,
		Meta = MetaValue
	};
}